#ifndef __LOCK_H_
#define __LOCK_H_
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#endif

#include "comdef.h"

class CLock
{
public:
	CLock(void)
	{
#ifdef WIN32
	::InitializeCriticalSection(&m_cs);
#endif		
	}

	~CLock(void)
	{
#ifdef WIN32
	::DeleteCriticalSection(&m_cs);
#endif	
	}

	void Lock()
	{
#ifdef WIN32
	::EnterCriticalSection(&m_cs);
#endif
	}

	void UnLock()
	{
#ifdef WIN32
	::LeaveCriticalSection(&m_cs);
#endif
	}

private:	
#ifdef WIN32
	CRITICAL_SECTION m_cs;
#endif
};

class CAutoLock
{
public:
	CAutoLock(CLock *pLock)
		:m_lock(pLock)
	{
		m_lock->Lock();
	}

	~CAutoLock()
	{
		m_lock->UnLock();
	}

private:
	CLock *m_lock;
};
#endif
